package CloudStorage;

import java.util.ArrayList;

public class Cart
{
    int id;
    int ownerId;
    ArrayList<File> files;

    public Cart()
    {
        files = new ArrayList<File>();
        this.ownerId = -1;
    }

    public Cart(int ownerId)
    {
        files = new ArrayList();
        this.ownerId = ownerId;
    }

    public Cart(int id, int ownerId)
    {
        this.id = id;
        this.ownerId = ownerId;
        files = new ArrayList();
    }

    public int getId() { return id; }

    public int getOwner () { return ownerId; }

    public void add ( File file)
    {
        files.add(file);
    }

    public int getSize()
    {
        return files.size();
    }

    public File getFile(int index)
    {
        return files.get(index);
    }

    public void remove(int index)
    {
        files.remove(index);
    }

    public int getIndex(int fileId)
    {
        for ( int i = 0; i < files.size(); i++ )
        {
            if ( files.get(i).getID() == fileId )
            {
                return i;
            }
        }

        return -1;
    }

    public boolean contains ( int fileId )
    {
        for ( int i = 0; i < files.size(); i++ )
        {
            if ( files.get(i).getID() == fileId )
            {
                return true;
            }
        }

        return false;
    }

    public ArrayList<File> getFiles() { return files; }

    @Override
    public String toString()
    {
        return files.toString();
    }


}
